package com.itheima.controller;

import com.itheima.common.response.ResponseResult;
import com.itheima.common.response.StatusCode;
import com.itheima.pojo.User;
import com.itheima.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @作者 itcast
 * @创建日期 2020/10/10 13:11
 **/
@RestController // Controller  ResponseBody
@RequestMapping("user")
public class UserController {
    @Autowired
    UserSerivce userSerivce;

    @GetMapping
    public ResponseResult findAll(){
        List<User> list = userSerivce.findAll();
        return ResponseResult.okResult(list);
    }
    @PostMapping
    public ResponseResult add(@RequestBody User user){
        int add = userSerivce.add(user);

        System.out.println(1/0);

        if(add > 0){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(StatusCode.USER_ADD_ERROR);
    }
}
